﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Cwing.UI.Validation;
using System.ComponentModel;
using Cwing.UI.Validation.Manager;

namespace Cwing.UI.Controls
{
    public class ValidationPage : System.Web.UI.Page
    {
        private PageValidationManager manager;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (!DesignMode)
            {
                manager = new PageValidationManager(this);
            }
        }

        public List<IValidation> ValidationControls
        {
            get { return manager.ValidationControls; }
        }

        public List<CustomizeValidation> CustomizeValidations
        {
            get
            {
                return manager.CustomizeValidations;
            }
        }

        /// <summary>
        /// trigger before first control validate begin
        /// </summary>
        public event PageValidating PageValidating
        {
            add
            {
                manager.PageValidating += value;
            }
            remove
            {
                manager.PageValidating -= value;
            }
        }

        /// <summary>
        /// trigger after all control validate finished
        /// </summary>
        public event PageValidated PageValidated
        {
            add
            {
                manager.PageValidated += value;
            }
            remove
            {
                manager.PageValidated -= value;
            }
        }

        /// <summary>
        /// execute control validate
        /// </summary>
        /// <returns></returns>
        public Boolean PageValidate()
        {
            return manager.PageValidate();
        }

        public Boolean PageValidate(String groupname)
        {
            return manager.PageValidate(groupname);
        }
    }
}
